package com.hulk.tenant.holder;


import com.hulk.tenant.util.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.InvalidParameterException;

/**
 * @author hulk
 * @date 2018/10/4
 * 租户工具类
 */
public class TenantContextRequestHeaderHolder implements TenantContextHolder {


	private static final String TENANT_ID = "organId";

	/**
	 * TTL 设置租户ID
	 *
	 * @param tenantId
	 */
	@Override
	public void setTenantId(String tenantId) {

	}

	/**
	 * 获取TTL中的租户ID
	 *
	 * @return
	 */
	@Override
	public String getTenantId() {
		HttpServletRequest req =  WebUtils.getRequest();
	    String tenantId =	req.getHeader(TENANT_ID);
	    if(StringUtils.isEmpty(tenantId)){
			tenantId="";
		}
	    return tenantId;

	}
	@Override
	public void clear() {

	}
}
